package com.itheima.exception;

import com.itheima.common.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

//全局异常处理器
@RestControllerAdvice
public class GlobalExceptionHandler  {



    @ExceptionHandler(DeleteCategoryException.class)
    public Result deleteCategoryException(DeleteCategoryException e){
        e.printStackTrace();
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result globalExceptionHandler(Exception e){
        e.printStackTrace();
        return Result.error("系统繁忙,请稍后再试");
    }

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public Result  sQLIntegrityConstraintViolationException(Exception e){
        e.printStackTrace();
        return Result.error("插入异常");
    }


}
